package com.irdstudio.cdp.pboc.service.impl;

import com.irdstudio.basic.framework.core.base.FrameworkService;
import com.irdstudio.cdp.pboc.service.dao.PbocCreditThousandDao;
import com.irdstudio.cdp.pboc.service.domain.PbocCreditThousand;
import com.irdstudio.cdp.pboc.service.facade.PbocCreditThousandService;
import com.irdstudio.cdp.pboc.service.vo.PbocCreditThousandVO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Objects;

/**
 * <p>ServiceImpl: 中征信“信用1000”评分信息				<p>
 * @author ligm
 * @date 2018-12-26
 */
@Service("pbocCreditThousandService")
public class PbocCreditThousandServiceImpl implements PbocCreditThousandService, FrameworkService {
	
	private static Logger logger = LoggerFactory.getLogger(PbocCreditThousandServiceImpl.class);

	@Autowired
	private PbocCreditThousandDao pbocCreditThousandDao;
	
	/**
	 * 新增操作
	 */
	public int insertPbocCreditThousand(PbocCreditThousandVO inPbocCreditThousandVo)  throws Exception {
		logger.debug("当前新增数据为:"+ inPbocCreditThousandVo.toString());
		int num = 0;
		try {
			PbocCreditThousand pbocCreditThousand = new PbocCreditThousand();
			beanCopy(inPbocCreditThousandVo, pbocCreditThousand);
			num = pbocCreditThousandDao.insertPbocCreditThousand(pbocCreditThousand);
		} catch (Exception e) {
			logger.error("新增数据发生异常!", e);
			num = -1;
			throw e;
		}
		logger.debug("当前新增数据条数为:"+ num);
		return num;
	}

	/**
	 * 删除操作
	 */
	public int deleteByPk(PbocCreditThousandVO inPbocCreditThousandVo)  throws Exception {
		logger.debug("当前删除数据条件为:"+ inPbocCreditThousandVo);
		int num = 0;
		try {
			PbocCreditThousand pbocCreditThousand = new PbocCreditThousand();
			beanCopy(inPbocCreditThousandVo, pbocCreditThousand);
			num = pbocCreditThousandDao.deleteByPk(pbocCreditThousand);
		} catch (Exception e) {
			logger.error("删除数据发生异常!", e);
			num = -1;
			throw e;
		}
		logger.debug("根据条件:"+ inPbocCreditThousandVo +"删除的数据条数为"+ num);
		return num;
	}


	/**
	 * 更新操作
	 */
	public int updateByPk(PbocCreditThousandVO inPbocCreditThousandVo)  throws Exception {
		logger.debug("当前修改数据为:"+ inPbocCreditThousandVo.toString());
		int num = 0;
		try {
			PbocCreditThousand pbocCreditThousand = new PbocCreditThousand();
			beanCopy(inPbocCreditThousandVo, pbocCreditThousand);
			num = pbocCreditThousandDao.updateByPk(pbocCreditThousand);
		} catch (Exception e) {
			logger.error("修改数据发生异常!", e);
			num = -1;
			throw e;
		}
		logger.debug("根据条件:"+ inPbocCreditThousandVo +"修改的数据条数为"+ num);
		return num;
	}
	
	/**
	 * 查询操作
	 */
	public PbocCreditThousandVO queryByPk(PbocCreditThousandVO inPbocCreditThousandVo) {
		
		logger.debug("当前查询参数信息为:"+ inPbocCreditThousandVo);
		try {
			PbocCreditThousand queryPbocCreditThousand = new PbocCreditThousand();
			beanCopy(inPbocCreditThousandVo, queryPbocCreditThousand);
			PbocCreditThousand queryRslPbocCreditThousand = pbocCreditThousandDao.queryByPk(queryPbocCreditThousand);
			if (Objects.nonNull(queryRslPbocCreditThousand)) {
				PbocCreditThousandVO outPbocCreditThousandVo = beanCopy(queryRslPbocCreditThousand, new PbocCreditThousandVO());
				logger.debug("当前查询结果为:"+ outPbocCreditThousandVo.toString());
				return outPbocCreditThousandVo;
			} else {
				logger.debug("当前查询结果为空!");
			}
		} catch (Exception e) {
			logger.error("查询数据发生异常!", e);
			throw e;
		}
		return null;
	}
//	@author:liuty
//	@date:2019/10/17
//	涉及产品:税e贷
//	功能:通过reportId查询
//	原因:增量投产只投了接口没投实现，编译报错因此注释，不影响实际业务
	
//    @Override
//    public PbocCreditThousandVO selectByReportId(PbocCreditThousandVO pbocCreditThousandVo) {
//
//        logger.debug("当前查询参数信息为:"+ pbocCreditThousandVo);
//        try {
//            PbocCreditThousand pbocCreditThousand = new PbocCreditThousand();
//            pbocCreditThousand = pbocCreditThousandDao.selectByReportId(pbocCreditThousandVo);
//            if (Objects.nonNull(pbocCreditThousand)) {
//                PbocCreditThousandVO pbocCreditThousandVO  = beanCopy(pbocCreditThousand, new PbocCreditThousandVO());
//                logger.debug("当前查询结果为:"+ pbocCreditThousandVO.toString());
//                return pbocCreditThousandVO;
//            } else {
//                logger.debug("当前查询结果为空!");
//            }
//        } catch (Exception e) {
//            logger.error("查询数据发生异常!", e);
//            throw e;
//        }
//        return null;
//    }


    /**
     * 查询用户权限数据
     */
    @SuppressWarnings("unchecked")
    public List<PbocCreditThousandVO> queryAllOwner(PbocCreditThousandVO pbocCreditThousandVo) throws Exception {

		logger.debug("当前查询本人所属数据信息的参数信息为:");
		List<PbocCreditThousandVO> list = null;
		try {
			List<PbocCreditThousand> pbocCreditThousands = pbocCreditThousandDao.queryAllOwnerByPage(pbocCreditThousandVo);
			logger.debug("当前查询本人所属数据信息的结果集数量为:"+ pbocCreditThousands.size());
			pageSet(pbocCreditThousands, pbocCreditThousandVo);
			list = (List<PbocCreditThousandVO>) beansCopy(pbocCreditThousands, PbocCreditThousandVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
			throw e;
		}
		
		return list;
	
	}


	/**
	 * 查询当前机构权限数据
	 */
	@SuppressWarnings("unchecked")
	public List<PbocCreditThousandVO> queryAllCurrOrg(PbocCreditThousandVO pbocCreditThousandVo)  throws Exception {

		logger.debug("当前查询本人所属机构数据信息的参数信息为:");
		List<PbocCreditThousand> pbocCreditThousands = pbocCreditThousandDao.queryAllCurrOrgByPage(pbocCreditThousandVo);
		logger.debug("当前查询本人所属机构数据信息的结果集数量为:"+pbocCreditThousands.size());
		List<PbocCreditThousandVO> list = null;
		try {
			pageSet(pbocCreditThousands, pbocCreditThousandVo);
			list = (List<PbocCreditThousandVO>) beansCopy(pbocCreditThousands, PbocCreditThousandVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
			throw e;
		}
		
		return list;
	
	}


	/**
	 * 查询当前机构及下属机构权限数据
	 */
	@SuppressWarnings("unchecked")
	public List<PbocCreditThousandVO> queryAllCurrDownOrg(PbocCreditThousandVO pbocCreditThousandVo)  throws Exception {

		logger.debug("当前查询本人所属机构及以下数据信息的参数信息为:");
		List<PbocCreditThousand> pbocCreditThousands = pbocCreditThousandDao.queryAllCurrDownOrgByPage(pbocCreditThousandVo);
		logger.debug("当前查询本人所属机构及以下数据信息的结果集数量为:"+ pbocCreditThousands.size());
		List<PbocCreditThousandVO> list = null;
		try {
			pageSet(pbocCreditThousands, pbocCreditThousandVo);
			list = (List<PbocCreditThousandVO>) beansCopy(pbocCreditThousands, PbocCreditThousandVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
			throw e;
		}
		
		return list;
	
	}
}
